<?php
class CrmModel{	

	/**
	 * zapis konfiguracji CRM do Bazy
	 * @return unknown_type
	 */
	protected function zapiszUstawieniaCrm(){
		global $config;
		foreach ($config->ustawienia_sklepu as $id => $wartosc) {
			$id__ = tools::__adodb('getOne',"SELECT id  FROM ".SKSETTIN." WHERE id = ".tools::__mres($id),true,$this->db); 
			if($id == $id__){
				tools::__adodb("exec","UPDATE ".SKSETTIN." SET wartosc = ".tools::__mres($wartosc)." WHERE id = ".tools::__mres($id),true,$this->db);
			}else{
				tools::__adodb("exec","INSERT INTO ".SKSETTIN." (id, wartosc) VALUES (".tools::__mres($id).",".tools::__mres($wartosc).");",true,$this->db);
			}
		}
	}	
	
	/**
	 * pobranie konfiguracji CRM z bazy
	 * @return unknown_type
	 */
	protected function pobiezUstawieniaCrm(){
		$q__ = "SELECT id, wartosc FROM ".SKSETTIN;
		return tools::__adodb('getAssoc',$q__,true,$this->db);
	}	
	
	protected function getProjectsList($status = null){
		
		$limity = '';
		$query = "SELECT COUNT(*) FROM ".CRPROJEK;		
		$razem =  tools::__adodb('getOne',$query,true,$this->db);
		$strona_docelowa = (!is_null($page))?$page:1;
		$ilosc_na_strone = 10;		
		$limity = tools::_stronicowanie($razem,$strona_docelowa,$ilosc_na_strone);

		$query = "SELECT * FROM ".CRPROJEK ." ".$limity;
		$result = tools::__adodb('getAll',$query,true,$this->db);
		return $result;	
	}
	
}